//公共函数库

var layer = require('layer');
var util = require('util');
var template = require('template');

return {
    getData:function(e, elem){
        if(elem.hasClass('table-row')){
            return elem.data();
        }
        return elem.closest('.table-row').data();
    },
    location:function(url){
        location.href = basePath + url
    },
    enabled:function(e, elem){
        return !elem.hasClass('ui-button-disabled')
    },
    print:function(url, params){
        if(util.isInstallPDF()){
            layer({
                height:160,
                content:renders({
                    <div class="f-tac e-pt20">
                        <i class="iconfont f-corange f-fs20 f-vam">&#xe608;</i>
                        <span class="f-dib e-mt-1 e-ml5 f-vam">打印需要借助PDF阅读器，请先下载！</span>
                    </div>
                }),
                button:[{
                    id:'cancel'
                },{
                    id:'download',
                    name:'normal',
                    text:'下载',
                    callback:function(){
                        util.location('http://rj.baidu.com/soft/detail/12612.html?ald', '_blank')
                    }
                }]
            })
            return false
        }
        this.request(url, params)
    },
    /**
     * @func 打开新窗口表单提交
     * @param url <String> 接口
     * @param params <Object> 参数
     */
    request:function(url, params){
        if(!url){
            return
        }
        var tpl = renders({
            <form class="f-dn" method="post" target="_blank" action="<%url%>">
                <%each params%>
                    <input type="hidden" name="<%index%>" value="<%$value%>">
                <%/each%>
            </form>
        })
        var form = $(template.render(tpl, {url:url, params:params})).appendTo('body');
        form.submit();
        form.remove();
    },
    /**
     * @func 验证用户权限对按钮进行隐藏
     * @param authoritys <String> 权限列表
     */
    verify:function(authoritys){
        if(authoritys){
            $('[authority]:not(.ui-button-disabled)').each(function(){
                var elem = $(this);
                var authority = elem.attr('authority');
                if(authoritys.indexOf(authority) === -1){
                    elem.addClass('ui-button-disabled s-dis')
                }
            });
        }
    }
}